package com.tulingxueyuan.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author li
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    @Qualifier("restTemplateNacos")
    private RestTemplate restTemplate;

    @RequestMapping("/add")
    public String add() {
        System.out.println("下单成功!");
        String msg = restTemplate.getForObject("http://stock-service/stock/reduce", String.class);
        return "hello world" + msg;
    }

    @RequestMapping("/header")
    public String header(@RequestHeader("X-Request-color") String color) {
        return color;
    }

    @RequestMapping("/get")
    public String get() {
        return "查询订单";
    }

    @RequestMapping("/flow")
    public String flow() {
        return "正常访问";
    }

    @RequestMapping("/flowThread")
    public String flowThread() throws InterruptedException {
        TimeUnit.SECONDS.sleep(6);
        return "正常访问";
    }

    @RequestMapping("/get/{id}")
    public String getById(@PathVariable("id") Integer id) {
        System.out.println("正常访问");
        return "正常访问";
    }
}
